/*
 * Ext JS Library 2.2 Copyright(c) 2006-2008, Ext JS, LLC. licensing@extjs.com
 * 
 * http://extjs.com/license
 */

// defines the Google Earth Plugin and google map js objects
var ge, map;
var geWin, mapwin, controlsWin;
// google.load("jquery", "1");
google.load("maps", "2.x");
google.load("earth", "1");

Ext.onReady(function() {

	var button_GE = Ext.get('show-ge-btn');
	var button = Ext.get('show-gm-btn');

	button.on('click', function() {
		// create the window on the first click and reuse on subsequent clicks
		if (!mapwin) {

			mapwin = new Ext.Window({
				layout : 'fit',
				title : 'GMap Window',
				closeAction : 'hide',
				width : 550,
				height : 550,
				x : 720,
				y : 23,
				closeAction : 'hide',
				draggable : true,
				plain : true,
				constrain : true,
				maximizable : true,

				items : {
					id : 'mapPanel',
					xtype : 'gmappanel',
					region : 'center',
					zoomLevel : 16,
					gmapType : 'map',
					mapConfOpts : ['enableScrollWheelZoom',
							'enableDoubleClickZoom', 'enableDragging'],
					mapControls : ['GSmallMapControl', 'GMapTypeControl',
							'NonExistantControl'],
					setCenter : {
						geoCodeAddr : '4 Yawkey Way, Boston, MA, 02215-3409, USA'
					}
					
				}
			});

		}

		mapwin.show();
		
		if (!controlsWin) {
					controlsWin= new Ext.Window({
								//applyTo : 'controlsDiv',
								title : 'Controls',
								//layout : 'fit',
								width : 340,
								height : 150,
								x : 700,
								y : 0,
								closeAction : 'hide',
								draggable : true,
								plain : true,
								constrain : true,
								maximizable : true,

								items: [
            new Ext.form.FieldSet({
                title: 'Police Vehicle Information',
                autoHeight: true,
                defaultType: 'textfield',
                items: [{
                        fieldLabel: 'Current Speed',
			   id: 'lblSpeed',
                        name: 'speed',
                        width:190
                    }, {
                        fieldLabel: 'Latitude',
			   id: 'lblLat',
                        name: 'lat',
                        width:190
                    }, {
                        fieldLabel: 'Longitude',
			   id: 'lblLon',
                        name: 'lon',
                        width:190
                    }

                ]
            }),
	     new Ext.Button({
		text: 'click'
		
		})
        ]
							});
				}

				//controlsWin.show();
				// geWin.maximize();



	});

	button_GE.on('click', function() {
				// create the GE window on the first click and reuse on
				// subsequent clicks
				if (!geWin) {
					geWin = new Ext.Window({
								applyTo : 'earthDiv',
								title : 'Google Earth View',
								layout : 'fit',
								width : 700,
								height : 550,
								x : 0,
								y : 23,
								closeAction : 'hide',
								draggable : true,
								plain : true,
								constrain : true,
								maximizable : true,

								buttons : [{
											text : 'Drive Mode',
											handler : function() {
												// geWin.hide();
												reposPolicecarToMelbourne();
												controlsWin.show();
											}
										}, {
											text : 'Free Fly Mode',
											handler : function() {
												// geWin.hide();
												delPoliceCar();
												controlsWin.hide();
											}
										}]
							});
				}

				geWin.show(button_GE);
				// geWin.maximize();

				if (!geInitialised) {
					setTimeout('initGE(geWin.body.dom.id)', 500);
				}
			});
	
	

});